package com.test.mooan.labama.utils_boom.analytics_boom.util_boom

import android.app.Application
//import com.google.firebase.FirebaseApp
import com.test.mooan.labama.utils_boom.analytics_boom.event_boom.IAnalyticsEvent_boom

//import com.test.mooan.labama.constants_boom.Url_boom
//import com.test.mooan.labama.utils_boom.analytics_boom.bean_boom.ParamFirebaseS2S_boom
//import com.test.mooan.labama.utils_boom.analytics_boom.http_boom.HttpHelper_boom
//import com.test.mooan.labama.utils_boom.analytics_boom.timezone_boom.TimeZoneUtil_boom
//import com.google.android.gms.tasks.Task
//import com.google.firebase.analytics.FirebaseAnalytics
//import com.google.firebase.analytics.ktx.analytics
//import com.google.firebase.analytics.ktx.logEvent
//import com.google.firebase.ktx.Firebase
//import com.google.gson.Gson

//tag2025
object FirebaseUtil_boom {

    /** 句柄 */
//    private var mFirebaseAnalytics: FirebaseAnalytics = Firebase.analytics

    /** firebase app id, 服务端回推firebase事件使用 */
    private var mFirebaseAppId: String = ""

    /** ga4 instance id, 服务端回推firebase事件使用 */
    private var mGa4InstanceId: String = ""

    /**
     * 初始化
     *
     * @param context Application
     */
    fun init(context: Application) {
//        try {
//
//            FirebaseApp.initializeApp(context);
//
//            if (mFirebaseAppId.isBlank()) {
//                Thread {
//                    mFirebaseAppId = FirebaseAnalytics.getInstance(context).firebaseInstanceId
//                    println("mFirebaseAppId=$mFirebaseAppId")
//                }.start()
//            }
//
//            if (mGa4InstanceId.isBlank()) {
//                val gResult: Task<String> = FirebaseAnalytics.getInstance(context).appInstanceId
//                gResult.addOnSuccessListener {
//                    mGa4InstanceId = it?:""
//                    println("mGa4InstanceId=$mGa4InstanceId")
//                }
//            }
//        } catch (e: Exception) {
//            e.printStackTrace()
//        }
    }

    /**
     * 打点
     *
     * @param event 事件名
     */
    fun addEvent(event: IAnalyticsEvent_boom) {
//        try {
//            when (event) {
//                IAnalyticsEvent_boom.AT_REGISTER -> {
//                    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SIGN_UP) {
//                        param(FirebaseAnalytics.Param.METHOD, IAnalyticsEvent_boom.AT_REGISTER.name)
//                    }
//                }
//                IAnalyticsEvent_boom.AT_BASIC -> {
//                    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LEVEL_UP) {
//                        param(
//                            FirebaseAnalytics.Param.CONTENT_TYPE,
//                            IAnalyticsEvent_boom.AT_BASIC.name
//                        )
//                        param(FirebaseAnalytics.Param.LEVEL, "1")
//                        param(FirebaseAnalytics.Param.SCORE, "100")
//                    }
//                }
//                IAnalyticsEvent_boom.AT_WORK -> {
//                    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.POST_SCORE) {
//                        param(FirebaseAnalytics.Param.CONTENT_TYPE, IAnalyticsEvent_boom.AT_WORK.name)
//                        param(FirebaseAnalytics.Param.CHARACTER, IAnalyticsEvent_boom.AT_WORK.name)
//                        param(FirebaseAnalytics.Param.LEVEL, "1")
//                        param(FirebaseAnalytics.Param.SCORE, "100")
//                    }
//                }
//                IAnalyticsEvent_boom.AT_CONTACT -> {
//                    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_SEARCH_RESULTS) {
//                        param(
//                            FirebaseAnalytics.Param.CONTENT_TYPE,
//                            IAnalyticsEvent_boom.AT_CONTACT.name
//                        )
//                        param(
//                            FirebaseAnalytics.Param.SEARCH_TERM,
//                            IAnalyticsEvent_boom.AT_CONTACT.name
//                        )
//                    }
//                }
//                IAnalyticsEvent_boom.AT_REV_CARD -> {
//                    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM) {
//                        param(
//                            FirebaseAnalytics.Param.CONTENT_TYPE,
//                            IAnalyticsEvent_boom.AT_REV_CARD.name
//                        )
//                    }
//                }
//                IAnalyticsEvent_boom.AT_LOAN_APPLY -> {
//                    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.PURCHASE) {
//                        param(
//                            FirebaseAnalytics.Param.CONTENT_TYPE,
//                            IAnalyticsEvent_boom.AT_LOAN_APPLY.name
//                        )
//                        param(
//                            FirebaseAnalytics.Param.AFFILIATION,
//                            IAnalyticsEvent_boom.AT_LOAN_APPLY.name
//                        )
//                        param(FirebaseAnalytics.Param.COUPON, IAnalyticsEvent_boom.AT_LOAN_APPLY.name)
//                        param(
//                            FirebaseAnalytics.Param.TRANSACTION_ID,
//                            IAnalyticsEvent_boom.AT_LOAN_APPLY.name
//                        )
//                        param(FirebaseAnalytics.Param.VALUE, "1")
//                        param(FirebaseAnalytics.Param.SHIPPING, "1")
//                        param(FirebaseAnalytics.Param.TAX, "1")
//                        param(FirebaseAnalytics.Param.CURRENCY, "USD")
//                    }
//                }
//                IAnalyticsEvent_boom.AT_REPAY -> {
//                    mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_COMPLETE) {
//                        param(
//                            FirebaseAnalytics.Param.CONTENT_TYPE,
//                            IAnalyticsEvent_boom.AT_REPAY.name
//                        )
//                        param(FirebaseAnalytics.Param.ITEM_ID, IAnalyticsEvent_boom.AT_REPAY.name)
//                    }
//                }
//            }
//        } catch (e: Exception) {
//            e.printStackTrace()
//        }
    }

    /**
     * 保存firebase s2s信息
     */
    fun saveS2SInfo(targetUrlList: List<String>) {
//        val params = ParamFirebaseS2S_boom()
//        val body = Gson().toJson(params).trim()
//        val resultTargetUrlList = TimeZoneUtil_boom.covertToRealTargetServers(targetUrlList)
//        println("====== $resultTargetUrlList")
//
//        //传多国时，里触发多次
//        resultTargetUrlList.forEach { path ->
//            val pathFormat =
//                if (path.endsWith(Url_boom.PATH_FIREBASE_S2S)) path else (path + Url_boom.PATH_FIREBASE_S2S)
//            HttpHelper_boom.postData(pathFormat, body)
//        }
    }

    /**
     * 获取Firebase App Id
     */
    fun getFirebaseAppId(): String {
        return mFirebaseAppId
    }

    /**
     * 获取Firebase Ga4 instance Id
     */
    fun getGa4InstanceId(): String {
        return mGa4InstanceId
    }
}